get_filename_component(TARGET ${CMAKE_CURRENT_SOURCE_DIR} NAME)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(QT NAMES Qt5 COMPONENTS Widgets Gui Core NetWork REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Gui Core NetWork REQUIRED)

FILE(GLOB SOURCE_FILES "./*.cpp")
FILE(GLOB HEAD_FILES "./*.h")

file(GLOB UI_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/ui_*.h")
file(GLOB_RECURSE MOC_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/mocs_*.cpp")
source_group("Generated Files" FILES ${UI_HEADERS})
source_group("Generated Files" FILES ${MOC_SOURCES})

add_executable(${TARGET} ${HEAD_FILES} ${SOURCE_FILES} ${RCC_FILES})
set_target_properties(${TARGET} PROPERTIES FOLDER "test") #将此工程分类到文件夹中

if(WIN32)
	# Visual Studio中的调试工作目录（即exe程序内的“./”所指的目录，仅在VS调试中有效）
	set_property(TARGET ${TARGET} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${OUT_ROOT_DIR}/bin/$<CONFIG>")
endif()

target_link_libraries(${TARGET} PRIVATE 
								Qt5::Core
								Qt5::Widgets
								Qt5::Gui
								Qt5::Network)

#隐藏console 控制台
###############################################################################
if(WIN32)
        if(MSVC)
                set_target_properties(${TARGET} PROPERTIES
                        WIN32_EXECUTABLE YES
                        LINK_FLAGS "/ENTRY:mainCRTStartup"
                )
        elseif(CMAKE_COMPILER_IS_GNUCXX)
                        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested
        else()
                message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
        endif(MSVC)
elseif(APPLE)
        set_target_properties(${TARGET} PROPERTIES
                        MACOSX_BUNDLE YES
        )
elseif(UNIX)
        # Nothing special required
else()
        message(SEND_ERROR "You are on an unsupported platform! (Not Win32, Mac OS X or Unix)")
endif(WIN32)
###############################################################################